----------------------------------Spell Variables--------------------------------------
SPELL.m_iSpellID = 1110 -- Whatever value you want as long as it doesn't override any other spells' IDs.
SPELL.m_iRange = 1024
SPELL.m_sName = "Frost Shock"
SPELL.m_sToolTip =	[[Bombard the target with
					  cold, dealing 5 frost
					  damage and slowing them.]]
SPELL.m_sIcon = "devin/blackbetty/spells/mage/frostshock.png"
SPELL.m_iCoolDown = 1
SPELL.m_iManaCost = 50
SPELL.m_bRequiresTarget = true
SPELL.m_iSpellType = SPELLTYPE_MAGICSLOW

---------------------------------------------------------------------------------------

function SPELL:Cast( pl, target )

	local weapon = nil
	local target = nil
	
	if(pl:IsPlayer())then
		weapon = pl:GetWeapon("weapon_all")
		target = pl:GetNetworkedEntity("Target")
	else
		target = pl.Target
	end
	
	local range = self.m_iRange
	if(target && target:IsValid() && target != pl) then
		pl.InSpellAnimation = true
		pl:EmitSound("devin/blackbetty/weapons/slam/swing_"..math.random(1,3)..".wav", 160, 100+math.random(20,30))
		ParticleEffectAttach( "frost_hands_instacast", PATTACH_POINT_FOLLOW, pl, pl:LookupAttachment("rightfoot"))
		ParticleEffect( "impact_frostbig", pl:GetPos() + Vector(0, 0, 45), Angle(0,0,0), pl )
			
		if(target and pl:GetPos():Distance(target:GetPos()) < self.m_iRange)then
			if(SERVER)then
				timer.Simple(0.1, function() 
					local hitdelay = ((pl:GetPos() - target:GetPos()):Length()/1600)
					pl:EmitSound("devin/blackbetty/weapons/castsounds/IceCast.wav", 80, 100+math.random(-10,10))
					if(pl:IsPlayer())then
						pl:DoAnimationEvent(ACT_HL2MP_GESTURE_RANGE_ATTACK_SLAM)
					else
						pl:RestartGesture(ACT_HL2MP_GESTURE_RANGE_ATTACK_SLAM)
					end
					local myhitdelay = ((pl:GetPos() - target:GetPos()):Length()/1800)
					ParticleEffect( "pummel_hit", pl:GetPos() + (pl:GetAngles():Forward()*48) + Vector(0, 0, 45) + (pl:GetAngles():Right()*16), Angle(0,0,0), pl )
					LaunchProjectile(pl, target, 0, "impact_frostbig", "", "frost_hands", "devin/blackbetty/weapons/travelsounds/IceMissileLoop.wav", myhitdelay, 1300, "models/crossbow_bolt.mdl")
					timer.Simple(hitdelay, function()
						local dmginfo = DamageInfo()
							if(weapon)then
								dmginfo:SetDamage( math.random(weapon.MinWeaponDamage, weapon.MaxWeaponDamage) )
							else
								dmginfo:SetDamage( math.random(pl.MinDamage, pl.MaxDamage) ) 
							end
							dmginfo:SetDamageType( DMG_GENERIC ) 
							dmginfo:SetAttacker( pl )
						target.Speed = true 
						target.SpeedMod = 0.5
						target.SpeedModDuration = 4
						target.SpeedType = "Charge"
						target:TakeDamageInfo( dmginfo )
						target:EmitSound("devin/blackbetty/weapons/hit/Ice1.wav", 140, 100+math.random(-10,10))
						ParticleEffect( "impact_frostbig", target:GetPos() + Vector(0, 0, 45), Angle(0,0,0), target )
					end)
				end)
			end
		end
		timer.Simple(0.3, function()
			pl.InSpellAnimation = false
			pl:SetNWBool("Casting", false)
			pl:SetNWBool("Casted", false)
		end)
	end
end




